package com.archstoday.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.archstoday.R;
import com.archstoday.entity.LikeListEntity;
import com.base.utils.ImageUtil;

import java.util.List;

public class LikeListAdapter extends BaseAdapter {

    private Context mContext;

    private List<LikeListEntity.DataBean> mData;

    public LikeListAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<LikeListEntity.DataBean> data) {
        mData = data;
        notifyDataSetChanged();
    }

    public void addData(List<LikeListEntity.DataBean> data) {
        mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mData != null) {
            return mData.size();
        }
        return 0;
    }

    @Override
    public LikeListEntity.DataBean getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_like_list, null);
            holder.imageIcon = (ImageView) view.findViewById(R.id.item_icon);
            holder.titleTv = (TextView) view.findViewById(R.id.item_title_tv);
            holder.typeTv = (TextView) view.findViewById(R.id.item_type_tv);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }

        ImageUtil.setCropBitmap(mContext, holder.imageIcon,
                mData.get(i).getImgs(), R.mipmap.default_icon);
        holder.titleTv.setText(mData.get(i).getTitle());
        holder.typeTv.setText(mData.get(i).getLabel());

        return view;
    }

    class Holder {
        ImageView imageIcon;
        TextView titleTv, typeTv;
    }
}